package com.ruoyi.web.controller.bus;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bus.domain.WitBusLocation;
import com.ruoyi.bus.service.IWitBusLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆位置Controller
 * 
 * @author caiyanshan
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/bus/location")
public class WitBusLocationController extends BaseController
{
    @Autowired
    private IWitBusLocationService witBusLocationService;

    /**
     * 查询车辆位置列表
     */
    @PreAuthorize("@ss.hasPermi('bus:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(WitBusLocation witBusLocation)
    {
        startPage();
        List<WitBusLocation> list = witBusLocationService.selectWitBusLocationList(witBusLocation);
        return getDataTable(list);
    }

    /**
     * 导出车辆位置列表
     */
    @PreAuthorize("@ss.hasPermi('bus:location:export')")
    @Log(title = "车辆位置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WitBusLocation witBusLocation)
    {
        List<WitBusLocation> list = witBusLocationService.selectWitBusLocationList(witBusLocation);
        ExcelUtil<WitBusLocation> util = new ExcelUtil<WitBusLocation>(WitBusLocation.class);
        return util.exportExcel(list, "location");
    }

    /**
     * 获取车辆位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('bus:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return AjaxResult.success(witBusLocationService.selectWitBusLocationById(locationId));
    }

    /**
     * 新增车辆位置
     */
    @PreAuthorize("@ss.hasPermi('bus:location:add')")
    @Log(title = "车辆位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WitBusLocation witBusLocation)
    {
        witBusLocationService.insertWitBusLocation(witBusLocation);
        return toAjax(1);
    }

    /**
     * 修改车辆位置
     */
    @PreAuthorize("@ss.hasPermi('bus:location:edit')")
    @Log(title = "车辆位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WitBusLocation witBusLocation)
    {
        return toAjax(witBusLocationService.updateWitBusLocation(witBusLocation));
    }

    /**
     * 删除车辆位置
     */
    @PreAuthorize("@ss.hasPermi('bus:location:remove')")
    @Log(title = "车辆位置", businessType = BusinessType.DELETE)
	  @DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(witBusLocationService.deleteWitBusLocationByIds(locationIds));
    }
}
